﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NHibernate;
using DBA.Data;
using DBA.Data.Hibernate;
using DBA.Model;
using DBA.Common;

namespace Demo
{
    public partial class demo_page5Modify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) return;
        }
        NHibernateQuery dal = CommonQuery.NHibernateQuery;


        protected void lbtn_Save_Click(object sender, EventArgs e)
        {

            Test_UserInfo userInfoModel = new Test_UserInfo();
            userInfoModel.UserName = "samfeng_" + new System.Random().Next().ToString();
            userInfoModel.Address = new System.Random().Next().ToString();
            userInfoModel.Email = new System.Random().Next().ToString();
            userInfoModel.IDcard = new System.Random().Next().ToString();
            userInfoModel.Mobile = new System.Random().Next().ToString();
            userInfoModel.Phone = new System.Random().Next().ToString();
            userInfoModel.PostalCode = new System.Random().Next(5).ToString();

            Test_UserInfo userInfoModel1 = new Test_UserInfo();
            userInfoModel1.UserName = "samfeng_" + new System.Random().Next().ToString();
            userInfoModel1.Address = new System.Random().Next().ToString();
            userInfoModel1.Email = new System.Random().Next().ToString();
            userInfoModel1.IDcard = new System.Random().Next().ToString();
            userInfoModel1.Mobile = new System.Random().Next().ToString();
            userInfoModel1.Phone = new System.Random().Next().ToString();
            userInfoModel1.PostalCode = new System.Random().Next(5).ToString();

            int value = 0;

            using (ITransaction tx = dal.CurrentSession.BeginTransaction())
            {
                try
                {
                    dal.InsertByTrans<Test_UserInfo>(userInfoModel);
                    dal.InsertByTrans<Test_UserInfo>(userInfoModel1);
                    dal.CurrentSession.Flush();
                    tx.Commit();
                    value = 1;
                }
                catch
                {
                    tx.Rollback();
                }
                
            }

            if (value == 1)
            {

                ScriptManager.RegisterStartupScript(this, base.GetType(), "insertOk" + System.Guid.NewGuid().ToString(), "Public.OpertAlert('数据添加成功',true);", true);
            }

        }
    }
}